﻿namespace Web.Control.WWW.Group
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text.RegularExpressions;
    using System.IO;
    using Lx.Web.Common.ControlsUI;
    using Lx.Web.Common.UI;
    using Model.WWW_WWW.Group;
    using BLF.WWW_WWW.Group;
    using System.Collections.Generic;
    using BLF;

    public class Search : BaseControl
    {
        /// <summary>
        /// 页面
        /// </summary>
        protected int pageIndex = 1;
        /// <summary>
        /// 语言
        /// </summary>
        protected string Learn = "";
        protected string memberno = "";
        /// <summary>
        /// 组的类型
        /// </summary>
        protected string gtype = "0";
        /// <summary>
        /// 关键字
        /// </summary>
        protected string key = "";
        protected Repeater repGroup;
        protected Repeater repTopic;
        protected Repeater rptLL;
        protected Literal lLCount;
        /// <summary>
        /// 数据数量
        /// </summary>
        protected int RecordCount = 0;
        protected List<TopicModel> tmList;
        protected List<GroupShModel> smList;
        ArrayList al = new ArrayList();
        protected string show = "1";
        protected override void OnLoad(EventArgs e)
        {
            int l = 15;
            if (lLCount != null) int.TryParse(lLCount.Text, out l);
            if (Request.Cookies["italkiLearn"] == null && Request.Cookies["italkiSpeak"] == null)
            {
                HttpCookie llCookie = new HttpCookie("italkiLearn", "all");
                HttpCookie blCookie = new HttpCookie("italkiSpeak", "all");
                Response.Cookies.Add(llCookie);
                Response.Cookies.Add(blCookie);
            }
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["p"] == "L")
                {
                    pageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out pageIndex);
                }
            }
            if (!string.IsNullOrEmpty(Request["key"]))
            {
                key = Request["key"].ToString();
            }
            if (!string.IsNullOrEmpty(Request["ll"]) && Request["ll"] != "")
            {
                Learn = Request["ll"];
                HttpCookie llCookie = new HttpCookie("italkiLearn", Learn);
                Response.Cookies.Add(llCookie);
                if (Request.Cookies["italkiSpeak"] == null)
                {
                    HttpCookie blCookie = new HttpCookie("italkiSpeak", "all");
                    Response.Cookies.Add(blCookie);
                }


            }
            else
            {
                Learn = Request.Cookies["italkiLearn"].Value;
            }
            if (!string.IsNullOrEmpty(Request["gtype"]))
            {
                gtype = Request["gtype"];
            }
            if (key.Trim() == "" || key.Trim().Length >= 3)
            {
                if (key.Trim() != "" || gtype != "0" || Learn != "")
                {
                    show = "0";
                    al = BLF.WWW_WWW.Group.Group.GetShGroups(key, Learn == "all" ? "" : Learn, gtype == "0" ? "" : gtype, pageIndex, l);
                    smList = al[0] as List<GroupShModel>;
                    RecordCount = al[1] == null ? 0 : (int)al[1];
                    tmList = al[2] as List<TopicModel>;
                }
            }
            else
            {
                show = "1";
                al = BLF.WWW_WWW.Group.Group.GetPrevail(Learn == "all" ? "" : Learn);
                tmList = al[0] as List<TopicModel>;
            }

            if (rptLL != null)
            {
                List<LanguageObj> lanObjList = new List<LanguageObj>();
                lanObjList.AddRange(BLF.StaticData.GetPopLanguageList);
                rptLL.DataSource = lanObjList;
                rptLL.DataBind();
            }
            if (repGroup != null)
            {
                repGroup.DataSource = smList;
                repGroup.DataBind();
            }
            if (repTopic != null)
            {
                repTopic.DataSource = tmList;
                repTopic.DataBind();
            }
            //标题
            this.DynamicTitle = GetText("GP534", new string[] { key });
            this.DynamicKeywords = GetText("GP535", new string[] { key });
            this.DynamicDescription = GetText("GP536", new string[] { key});
        }
    }
}